package com.sanjiahantang.youjiarole.module.goods.presenters;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.sanjiahantang.uilibrary.adapter.listview.BaseAdapterHelper;
import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.uilibrary.views.Lable;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseApplication;
import com.sanjiahantang.youjiarole.base.BaseBean;
import com.sanjiahantang.youjiarole.base.BaseMvpPresenter;
import com.sanjiahantang.youjiarole.base.BaseView;
import com.sanjiahantang.youjiarole.base.CallBack;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.config.SPConfig;
import com.sanjiahantang.youjiarole.module.cases.models.ICaseModel;
import com.sanjiahantang.youjiarole.module.cases.models.impl.CaseModel;
import com.sanjiahantang.youjiarole.module.common.beans.ConditionBean;
import com.sanjiahantang.youjiarole.module.common.beans.StringBean;
import com.sanjiahantang.youjiarole.module.goods.adapters.GoodsInfoAdapter;
import com.sanjiahantang.youjiarole.module.goods.adapters.GoodsListMoreAdapter;
import com.sanjiahantang.youjiarole.module.goods.beans.CartNum;
import com.sanjiahantang.youjiarole.module.goods.beans.GoodsAttrBean;
import com.sanjiahantang.youjiarole.module.goods.beans.GoodsBean;
import com.sanjiahantang.youjiarole.module.goods.beans.GoodsListBean;
import com.sanjiahantang.youjiarole.module.goods.beans.GoodsSelectorBean;
import com.sanjiahantang.youjiarole.module.goods.models.IGoodsModel;
import com.sanjiahantang.youjiarole.module.goods.models.impl.GoodsModel;
import com.sanjiahantang.youjiarole.module.goods.views.GoodsView;
import com.sanjiahantang.youjiarole.module.login.views.impl.LoginActivity;
import com.sanjiahantang.youjiarole.module.match.beans.MatchBean;
import com.sanjiahantang.youjiarole.module.me.favorite.views.FavoriteCaseView;
import com.sanjiahantang.youjiarole.module.me.order.views.impl.OrderActivity;
import com.sanjiahantang.youjiarole.utils.FileUtils;
import com.sanjiahantang.youjiarole.utils.SPUtils;
import com.squareup.picasso.Picasso;

import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.CommonPagerTitleView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zy on 2017/9/20.
 */

public class GoodsPresenter extends BaseMvpPresenter<GoodsView> {
    private GoodsInfoAdapter infoAdapter;
    private BaseView.OnLoadListener onLoadListener;
    private IGoodsModel goodsModel;
    private Dialog attrDialog;
    private int page;
    private GoodsListMoreAdapter listMoreAdapter;
    private List<MatchBean.Goods> listData;
    private boolean canLoadMore;
    private ICaseModel caseModel;
    private QuickAdapter selectorAdapter;

    private List<ConditionBean.SelectorData> styleList,bandList,currentList;
    private int bandId;
    private String currentStyle;
    private String keyWord;
    private int isExperienceShow;
    private int startMoney,endMoney,categoryId;
    private List<GoodsAttrBean.SkuData> skuData;
    private GoodsBean goodsBean;
    private String orderCode,typeGoodsId;
    private String isadd,goodsadd,findsimilar;

    public GoodsPresenter(){
        goodsModel = new GoodsModel();
        listData = new ArrayList<>();
        caseModel = new CaseModel();
        styleList = new ArrayList<>();
        bandList = new ArrayList<>();
    }

    private int pageNo = 1;
    public void loadGoodDetail(final Context context, final int goodsID, boolean refresh, final String goodsadd, BaseView.OnLoadListener listener) {
        this.goodsadd=goodsadd;
        this.onLoadListener = listener;
        if (refresh){
            pageNo = 1;
        }
        Map<String,Object> param = new HashMap<>();
        if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)){
            param.put(KEY_TOKEN,ConfigValue.DATA_KEY);
        }
        param.put(KEY_PAGE_SIZE,PAGE_SIZE);
        param.put(KEY_PAGE,pageNo);
        Map<String,Object> map = new HashMap<>();
        String phone = SPUtils.get(context, SPConfig.PHONE,"").toString();
        if (!TextUtils.isEmpty(phone)){
            map.put(KEY_PHONE,phone);
        }
        map.put(KEY_ID,goodsID);
        map.put("role",SPUtils.get(context,SPConfig.ROLE_ID,"").toString());
        param.put(KEY_PARAM,map);
        mView.showProgress();
        goodsModel.getGoodDetail(context,param,new  CallBack<GoodsBean>(){
            @Override
            public void onSuccess(GoodsBean response, final Context context, Object tag) {
                if (mView == null) return;
                hideProgress();
                if (response.getCode() == RESPONSE_CODE_SUC){
                    if (pageNo == 1){
                        infoAdapter = new GoodsInfoAdapter(response.getData(), (Activity) context,GoodsPresenter.this);
                        infoAdapter.setGoodsType(goodsadd);
                        if (page == 0){
                            Object[] obj = new Object[2];
                            obj[0] = CALLBACK_TYPE_RECYCLER_ADAPTER;
                            obj[1] = infoAdapter;
                            onLoadListener.onLoad(obj);
                        }else{
                            Object[] obj = new Object[2];
                            obj[0] = CALLBACK_TYPE_LIST;
                            obj[1] = response.getData().getGoodsRecommendList();
                            onLoadListener.onLoad(obj);
                        }

                        goodsBean = response;

                        Object[] obj2 = new Object[2];
                        obj2[0] = CALLBACK_TYPE_GOODS_DETAIL;
                        obj2[1] = goodsBean.getData();
                        onLoadListener.onLoad(obj2);

                        infoAdapter.setParamOnClickLister(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                showParamData(context,goodsID);
                            }
                        });


                        if (goodsadd == null){
                            refreshShoppingCart(context);
                        }
                    }else {
                        GoodsListBean.Data list = response.getData().getGoodsRecommendList();
                        Object[] obj = new Object[2];
                        obj[0] = CALLBACK_TYPE_MORE;
                        obj[1] = list;
                        onLoadListener.onLoad(obj);
                    }
                    pageNo++;

                }else{
                    Object[] obj = new Object[2];
                    obj[0] = CALLBACK_TYPE_FAILURE;
                    onLoadListener.onLoad(obj);
                }

            }

            @Override
            public void onFailure(String message) {
                if (mView == null) return;
                hideProgress();
                Object[] obj = new Object[2];
                obj[0] = CALLBACK_TYPE_FAILURE;
                onLoadListener.onLoad(obj);
            }
        });
        attrDialog = new Dialog(context, R.style.Dialog_Fullscreen);
        attrDialog.setContentView(R.layout.dialog_goods_attr);
    }

    private Dialog paramDialog;
    /**
     * 获取商品参数规格
     * 2018-4-19
     * @param context
     * @param goodsID
     */
    private void showParamData(Context context, int goodsID) {
        if (paramDialog != null){
            paramDialog.show();
            return;
        }else{
            paramDialog = new Dialog(context,R.style.Dialog_Fullscreen);
            View paramDialogPanel = LayoutInflater.from(context).inflate(R.layout.dialog_param,null);
            paramDialog.setContentView(paramDialogPanel);
            paramDialogPanel.findViewById(R.id.btnOk).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    paramDialog.dismiss();
                }
            });
            ListView listView = (ListView) paramDialogPanel.findViewById(R.id.listView);
            listView.setAdapter(new QuickAdapter<HashMap<String,String>>(context,R.layout.item_param) {
                @Override
                protected void convert(BaseAdapterHelper helper, HashMap<String, String> item) {
                    helper.setText(R.id.tvKey,item.get("detailName"));
                    helper.setText(R.id.tvValue,item.get("detailValue"));
                }
            });
        }
        findGoodsSpecifionsDetailInfo(context,goodsID);
    }

    private void findGoodsSpecifionsDetailInfo(Context context, int goodsID) {
        Map<String,String> map = new HashMap<>();
        map.put("mgiId",String.valueOf(goodsID));
        goodsModel.findGoodsSpecifionsDetailInfo(context,map, new CallBack<StringBean>() {
            @Override
            public void onSuccess(StringBean response, Context context, Object tag) {
                if (mView == null) return;
                hideProgress();
                if (response.getCode() == RESPONSE_CODE_SUC){
                    List<HashMap<String,String>> listMap = new ArrayList<>();
                    try{
                        listMap = new Gson().fromJson(response.getData(),new TypeToken<List<HashMap<String,String>>>(){}.getType());
                    }catch(Exception e){

                    }

                    ListView listView = (ListView) paramDialog.findViewById(R.id.listView);
                    QuickAdapter<HashMap<String,String>> adapter = (QuickAdapter<HashMap<String, String>>) listView.getAdapter();
                    adapter.addAll(listMap);
                    paramDialog.show();
                }else {
                    paramDialog = null;
                }
            }

            @Override
            public void onFailure(String message) {
                if (mView == null) return;
                hideProgress();
                paramDialog = null;
            }
        });
    }
    public void addCollectInfo(final Context context, int goodsID) {
        mView.showProgress();
        Map<String,Object> param = new HashMap<>();
        param.put(KEY_TOKEN,ConfigValue.DATA_KEY);
        param.put(FavoriteCaseView.KEY_ROLE_TYPE,0);
        param.put(KEY_PHONE,SPUtils.get(context, SPConfig.PHONE,"").toString());
        param.put(KEY_TYPE,0);
        param.put(FavoriteCaseView.KEY_FAVORITE_ID,goodsID);
        goodsModel.addCollectInfo(context, param, new CallBack<BaseBean>() {
            @Override
            public void onSuccess(BaseBean response, Context context, Object tag) {
                if (mView == null) return;
                hideProgress();
                Utils.showToast(context,response.getMessage());
                if (response.getCode() == RESPONSE_CODE_SUC){
                    Object[] param = new Object[2];
                    param[0] = CALLBACK_TYPE_BOOLEAN;
                    param[1] = true;
                    onLoadListener.onLoad(param);
                }else{
                    Object[] param = new Object[2];
                    param[0] = CALLBACK_TYPE_BOOLEAN;
                    param[1] = false;
                    onLoadListener.onLoad(param);
                }
            }

            @Override
            public void onFailure(String message) {
                if (mView == null) return;
                hideProgress();
                Utils.showToast(context,message);
                Object[] param = new Object[2];
                param[0] = CALLBACK_TYPE_BOOLEAN;
                param[1] = false;
                onLoadListener.onLoad(param);
            }
        });
    }

    public void deleteCollectInfo(final Context context, int goodsID) {
        mView.showProgress();
        Map<String,Object> param = new HashMap<>();
        param.put(KEY_TOKEN,ConfigValue.DATA_KEY);
        param.put(FavoriteCaseView.KEY_ROLE_TYPE,0);
        param.put(KEY_PHONE,SPUtils.get(context, SPConfig.PHONE,"").toString());
        param.put(KEY_TYPE,0);
        param.put(FavoriteCaseView.KEY_FAVORITE_ID,goodsID);
        caseModel.deleteCollectInfo(context,param, new CallBack<BaseBean>() {
            @Override
            public void onSuccess(BaseBean response, Context context, Object tag) {
                if (mView == null) return;
                hideProgress();
                Utils.showToast(context,response.getMessage());
                if (response.getCode() == RESPONSE_CODE_SUC){
                    Object[] param = new Object[2];
                    param[0] = CALLBACK_TYPE_BOOLEAN;
                    param[1] = false;
                    onLoadListener.onLoad(param);
                }else{
                    Object[] param = new Object[2];
                    param[0] = CALLBACK_TYPE_BOOLEAN;
                    param[1] = true;
                    onLoadListener.onLoad(param);
                }
            }

            @Override
            public void onFailure(String message) {
                if (mView == null) return;
                hideProgress();
                Utils.showToast(context,message);
                Object[] param = new Object[2];
                param[0] = CALLBACK_TYPE_BOOLEAN;
                param[1] = true;
                onLoadListener.onLoad(param);
            }
        });
    }





    public void showAttrDialog() {
        attrDialog.show();
    }

    public void loadGoodAttr(Context context,int goodsId,final boolean isFromCart,String add){
        this.isadd=add;
        mView.showProgress();
        Map<String,String> param = new HashMap<>();
        if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)){
            param.put(KEY_TOKEN,ConfigValue.DATA_KEY);
        }else{
            LoginActivity.logout(context);
            return;
        }
        param.put("mgiId",String.valueOf(goodsId));
        goodsModel.loadGoodsAttr(context,param, new CallBack<GoodsAttrBean>() {
            @Override
            public void onSuccess(GoodsAttrBean response, Context context, Object tag) {
                if (mView == null) return;
                hideProgress();
                if (response.getCode() == RESPONSE_CODE_SUC){
                    fillAttrDialog(context,response.getData(),isFromCart,isadd);
                    attrDialog.show();
                }

            }

            @Override
            public void onFailure(String message) {
                if (mView == null) return;
                hideProgress();
            }
        });

    }



    private int attrNum = 1;
    private int attrStock = 1;
    private void fillAttrDialog(final Context context, final GoodsAttrBean.Data data, final boolean isFromCart,final String isadd) {
        Picasso picasso = Picasso.with(context);
        Lable lbPropertyList = (Lable) attrDialog.findViewById(R.id.lbPropertyList);
        final ImageView iv = (ImageView) attrDialog.findViewById(R.id.ivGoodsImage);
        TextView txtGoodsName = (TextView) attrDialog.findViewById(R.id.txtGoodsName);
        TextView txtPrice = (TextView) attrDialog.findViewById(R.id.txtGoodsPrice);
        View add = attrDialog.findViewById(R.id.number_add);
        View min = attrDialog.findViewById(R.id.number_sub);
        final TextView txtNum = (TextView) attrDialog.findViewById(R.id.goods_number);
        View submit = attrDialog.findViewById(R.id.btnOK);
        TextView total = (TextView) attrDialog.findViewById(R.id.txtStock);

        View.OnClickListener defaultOnClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Utils.showToast(context,"没有可选的规格!");
            }
        };

        if (goodsBean != null && goodsBean.getData() != null){
            picasso.load(FileUtils.rePath(goodsBean.getData().getUrl())).placeholder(RES_ID_GOODS_DEFAULT).into(iv);
            txtGoodsName.setText(goodsBean.getData().getGoodsName());
            if (data.getSkuData().size() == 0){
                Utils.showToast(context,"加载商品规格错误!");
                attrDialog.dismiss();
                return;
            }
            attrStock = data.getSkuData().get(0).getStockCount();
            add.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (attrNum < attrStock){
                        attrNum++;
                    }

                    txtNum.setText(String.valueOf(attrNum));
                }
            });

            min.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (attrNum > 1){
                        attrNum--;
                    }
                    txtNum.setText(String.valueOf(attrNum));
                }
            });

//            if (goodsBean.getData().getImgUrlList() != null && goodsBean.getData().getImgUrlList().size() > 0){
//                picasso.load(ConfigValue.IMG_IP + goodsBean.getData().getImgUrlList().get(0).getUrl()).placeholder(R.drawable.i_rect_bg).error(R.drawable.i_rect_bg).into(iv);
//            }
        }

        if (data.getSkuData() != null && data.getSkuData().size() > 0){

            txtPrice.setText(data.getSkuData().get(0).getResultPrice());
            int stockCount = data.getSkuData().get(0).getStockCount();
            if (stockCount < 0){
                stockCount = 0;
            }
            total.setText(String.valueOf(stockCount));
            List<String> arr = new ArrayList<>();
            List<Boolean> bol = new ArrayList<>();
            int firstIndex = -1;
            for (int i = 0,max = data.getSkuData().size();i<max;i++){
                arr.add(data.getSkuData().get(i).getMgpiValue());
                if (data.getSkuData().get(i).getStockCount() > 0){
                    bol.add(true);
                    if (firstIndex == -1){
                        firstIndex = i;
                    }
                }else {
                    bol.add(false);
                }
            }
            lbPropertyList.setDataList(arr);
            lbPropertyList.setItemClickable(bol);
            lbPropertyList.setOnItemSelectClickListener(new Lable.OnItemSelectClickListener() {
                @Override
                public void selectclick(String text, int position) {
                    int index = position - 1;
                    if (index < 0){
                        index = 0;
                    }

                    if (index > data.getSkuData().size() - 1){
                        index = data.getSkuData().size() - 1;
                    }
                    final GoodsAttrBean.SkuData sku = data.getSkuData().get(index);
                    TextView txtPrice = (TextView) attrDialog.findViewById(R.id.txtGoodsPrice);
                    View submit = attrDialog.findViewById(R.id.btnOK);
                    View btn_beSure=attrDialog.findViewById(R.id.btn_beSure);
                    TextView total = (TextView) attrDialog.findViewById(R.id.txtStock);
                    final TextView txtNum = (TextView) attrDialog.findViewById(R.id.goods_number);

                    int price = 0;
                    if (goodsBean.getData().getIsSale() == 1){
                        price = (int) goodsBean.getData().getSalePrice();
                    }else{
                        price = (int) goodsBean.getData().getBasePrice();
                    }

                    txtPrice.setText(sku.getResultPrice());

                    attrStock = sku.getStockCount();
                    attrNum = Integer.parseInt(txtNum.getText().toString());
                    if (attrNum > attrStock){
                        txtNum.setText(String.valueOf(attrStock));
                    }else {
                        txtNum.setText(String.valueOf(attrNum));
                    }
                    total.setText(String.valueOf(attrStock));
                    if (isadd==null){
                        btn_beSure.setVisibility(View.GONE);
                        submit.setVisibility(View.VISIBLE);
                    }else {
                        btn_beSure.setVisibility(View.VISIBLE);
                        submit.setVisibility(View.GONE);
                    }
                    //增项目
                    btn_beSure.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Object[] objects = new Object[4];
                            objects[0] = goodsBean.getData();
                            objects[1] = sku;
                            objects[2] = txtNum.getText().toString();
                            objects[3]=isadd;
                            ConfigValue.param = objects;
                            ((Activity)context).finish();
                            BaseApplication.clearActivity();
                        }
                    });
                    submit.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            HashMap<String,Object> param = new HashMap<>();
                            param.put(KEY_TOKEN,ConfigValue.DATA_KEY);
                            param.put(KEY_PHONE,SPUtils.get(context,SPConfig.PHONE,"").toString());
                            param.put("skuId",sku.getSkuId());
                            param.put("number",attrNum);
                            param.put("typeGoodsId",goodsBean.getData().getTypeGoodsId());
                            param.put("mgiId",goodsBean.getData().getMgiId());
                            param.put("mgpiValue",sku.getMgpiValue());
                            mView.showProgress();
                            if (isFromCart){

                                goodsModel.addShoppingCartInfoForCustomer(context,param, new CallBack<BaseBean>() {
                                    @Override
                                    public void onSuccess(BaseBean response, Context context, Object tag) {
                                        if (mView == null) return;
                                        hideProgress();
                                        Utils.showToast(context,response.getMessage());
                                        attrDialog.dismiss();
                                        if (isadd == null){
                                            refreshShoppingCart(context);
                                        }
                                    }

                                    @Override
                                    public void onFailure(String message) {
                                        if (mView == null) return;
                                        hideProgress();
                                        Utils.showToast(context,message);
                                    }
                                });
                            }else{
                                Intent intent = new Intent(context,OrderActivity.class);
                                Bundle b = new Bundle();
                                GoodsBean.Data data = new GoodsBean.Data();
                                data.setMgiId(goodsBean.getData().getMgiId());
                                data.setGoodsName(goodsBean.getData().getGoodsName());
                                data.setUrl(goodsBean.getData().getUrl());
                                data.setMgcId(goodsBean.getData().getMgcId());
                                data.setBasePrice(goodsBean.getData().getBasePrice());
                                data.setSalePrice(goodsBean.getData().getSalePrice());
                                data.setIsSale(goodsBean.getData().getIsSale());
                                data.setSupplyId(goodsBean.getData().getSupplyId());
                                data.setSupplyName(goodsBean.getData().getSupplyName());
                                b.putSerializable("goods",data);
                                b.putSerializable("sku",sku);
                                b.putInt("num",attrNum);
                                intent.putExtra(KEY_PARAM,b);
                                intent.putExtra(KEY_TYPE,ORDER_TYPE_GOODS);
                                context.startActivity(intent);
                                attrDialog.dismiss();
                                hideProgress();
                            }
                        }
                    });
                }
            });
            if (firstIndex > -1){
                lbPropertyList.getChildAt(firstIndex).performClick();
            }else{
                submit.setOnClickListener(defaultOnClickListener);
                attrDialog.findViewById(R.id.btn_beSure).setOnClickListener(defaultOnClickListener);
            }
        }else{
            submit.setOnClickListener(defaultOnClickListener);
            attrDialog.findViewById(R.id.btn_beSure).setOnClickListener(defaultOnClickListener);
        }


    }


    public void getMoreList(Context context) {
        if(canLoadMore){
            page++;
            Map<String,Object> params = goodsListParam;
            params.put(GoodsView.KEY_PAGE,String.valueOf(page));
            goodsModel.resetGoodsList(context,params,new MoreGoodsListCallBack());
        }else {
            Utils.showToast(context,"已经到底了!!");
        }

    }

    public void resetGoodsList(Context context,int startMoney,int endMoney){
        this.startMoney = startMoney;
        this.endMoney = endMoney;
        resetGoodsList(context);
    }
    Map<String,Object> goodsListParam;
    public void resetGoodsList(Context context) {
        page = 1;
        canLoadMore = true;
        mView.showProgress();
        Map<String,Object> params = new HashMap<>();
        params.put(KEY_PAGE, page);
        params.put(KEY_PAGE_SIZE, PAGE_SIZE);

        Map<String,Object> map = new HashMap<>();
        if (keyWord != null){
            map.put("keyWord",keyWord);
        }

        if (typeGoodsId != null)
            map.put(KEY_TYPE_GOODSID,typeGoodsId);
        if (currentStyle != null){
            map.put("styleGoodsId",currentStyle);
        }

        if (bandId != 0){
            map.put("mbiId",bandId);
        }

        if (startMoney > 0){
            map.put("startMoney",startMoney);
        }

        if (endMoney > 0 && endMoney < DEFAULT_PAGE_SIZE / 2){
            map.put("endMoney",endMoney);
        }

        if (categoryId > 0){
            map.put("mgcId",categoryId);
        }

        if (isExperienceShow == 1){
            map.put("isExperienceShow",1);
        }

        if (!TextUtils.isEmpty(orderCode)){
            map.put("orderCode",orderCode);
        }

        map.put("roleId",SPUtils.get(context,SPConfig.ROLE_ID,"").toString());
        params.put(KEY_PARAM,map);
        goodsListParam = params;
        goodsModel.resetGoodsList(context,params,new ResetGoodsListCallBack());
        if(listMoreAdapter == null){
            listMoreAdapter = new GoodsListMoreAdapter(context,listData,null,typeGoodsId,findsimilar);
            Object[] obj = new Object[2];
            obj[0] = CALLBACK_TYPE_RECYCLER_ADAPTER;
            obj[1] = listMoreAdapter;
            onLoadListener.onLoad(obj);
        }

    }

    private class ResetGoodsListCallBack implements CallBack<GoodsListBean>{

        @Override
        public void onSuccess(GoodsListBean response, Context context, Object tag) {
            if (mView == null) return;
            if (response == null || response.getData() == null || response.getData().getList() == null) return;
            hideProgress();
            listData.clear();
            listData.addAll(response.getData().getList());
            listMoreAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFailure(String message) {
            if (mView == null) return;
            hideProgress();
        }
    }

    private class MoreGoodsListCallBack implements CallBack<GoodsListBean>{

        @Override
        public void onSuccess(GoodsListBean response, Context context, Object tag) {
            if (mView == null)return;
            hideProgress();
            if(response == null || response.getData() == null || response.getData().getList() == null || response.getData().getList().size() == 0){
                canLoadMore = false;
                return;
            }
            listData.addAll(response.getData().getList());
//            listMoreAdapter = new GoodsListMoreAdapter(context,listData,null);
//            onLoadListener.initRecyclerView(listMoreAdapter);

            listMoreAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFailure(String message) {
            if (mView == null)return;
            hideProgress();
        }
    }

    public void setOnLoadListener(BaseView.OnLoadListener onLoadListener) {
        this.onLoadListener = onLoadListener;
    }


    public void loadSelectors(Context context, final int category_Id, final String key_word, int isExperienceShow, final String code,
                              final String typeGoods_Id,final String find_similar){
        mView.showProgress();
        this.isExperienceShow = isExperienceShow;
        Map<String,String> param = new HashMap<>();
        if (TextUtils.isEmpty(code)){
            param.put("mgcId","0");
        }else{
            param.put("mgcId",code);
        }
        goodsModel.loadSelectors(context, param,new CallBack<GoodsSelectorBean>() {
            @Override
            public void onSuccess(GoodsSelectorBean response, Context context, Object tag) {
                if (mView == null) return;
                if (response == null || response.getCode() != RESPONSE_CODE_SUC){
                    return;
                }
                styleList = response.getData().getGoodsStyleList();
                bandList = response.getData().getGoodsBrandList();
                categoryId = category_Id;
                keyWord = key_word;
                orderCode = code;
                startMoney = -1;
                endMoney = DEFAULT_PAGE_SIZE;

                currentStyle = null;
                bandId = 0;

                if (!TextUtils.isEmpty(typeGoods_Id)){
                    typeGoodsId=typeGoods_Id;
                }
                if (find_similar!=null){
                    findsimilar=find_similar;
                }
                resetGoodsList(context);
                selectorAdapter = new QuickAdapter<ConditionBean.SelectorData>(context, android.R.layout.simple_list_item_1) {
                    @Override
                    protected void convert(BaseAdapterHelper helper, final ConditionBean.SelectorData item) {
                        helper.setText(android.R.id.text1,item.getName());
                        helper.getView().setBackgroundColor(Color.WHITE);
                        helper.setOnClickListener(android.R.id.text1, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                if (item.getParentId() == null){
                                    //band
                                    if (item.getDicValue() == null){
                                        bandId = 0;
                                    }else{
                                        bandId = Integer.parseInt(item.getDicValue());
                                    }
                                }else{
                                    currentStyle = item.getDicValue();
                                }

                                resetGoodsList(context);
                                Object[] obj = new Object[2];
                                obj[0] = CALLBACK_TYPE_RECOVER;
                                obj[1] = item;
                                onLoadListener.onLoad(obj);
                            }
                        });
                    }

                };
                Object[] obj = new Object[2];
                obj[0] = CALLBACK_TYPE_QUICK_ADAPTER;
                obj[1] = selectorAdapter;
                onLoadListener.onLoad(obj);

                final List<GoodsSelectorBean.Category> categoryList = response.getData().getCategoryList();
                if (categoryList != null && categoryList.size() > 0){
                    final List<RadioButton> radioButtonList = new ArrayList<>();
                    GoodsSelectorBean.Category allBean = new GoodsSelectorBean.Category();
                    allBean.setName("全部");
                    allBean.setMgcId(orderCode);
                    categoryList.add(0,allBean);
                    CommonNavigatorAdapter adapter = new CommonNavigatorAdapter() {
                        @Override
                        public int getCount() {
                            return categoryList.size();
                        }

                        @Override
                        public IPagerTitleView getTitleView(final Context context, final int index) {
                            CommonPagerTitleView commonPagerTitleView = new CommonPagerTitleView(context);
                            View contentView = LayoutInflater.from(context).inflate(R.layout.item_radio_line, null);
                            commonPagerTitleView.setContentView(contentView);
                            final RadioButton btn = (RadioButton) contentView.findViewById(R.id.rbItem);
                            btn.setText(categoryList.get(index).getName());
                            btn.setTag(R.id.decode,categoryList.get(index).getMgcId());
                            radioButtonList.add(btn);
                            commonPagerTitleView.setOnPagerTitleChangeListener(new CommonPagerTitleView.OnPagerTitleChangeListener() {
                                @Override
                                public void onSelected(int i, int i1) {
                                    btn.setChecked(true);
                                }

                                @Override
                                public void onDeselected(int i, int i1) {
                                    btn.setChecked(false);
                                }

                                @Override
                                public void onLeave(int i, int i1, float v, boolean b) {

                                }

                                @Override
                                public void onEnter(int i, int i1, float v, boolean b) {

                                }
                            });
                            btn.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    for (RadioButton radioButton : radioButtonList){
                                        radioButton.setChecked(false);
                                    }
                                    btn.setChecked(true);
                                    orderCode = (String) v.getTag(R.id.decode);
                                    resetGoodsList(context);
                                }
                            });
                            commonPagerTitleView.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    for (RadioButton radioButton : radioButtonList){
                                        radioButton.setChecked(false);
                                    }
                                    btn.setChecked(true);
                                    orderCode = (String) v.getTag(R.id.decode);
                                    resetGoodsList(context);
                                }
                            });
                            return commonPagerTitleView;
                        }

                        @Override
                        public IPagerIndicator getIndicator(Context context) {
                            return null;
                        }
                    };
                    Object[] obj2 = new Object[2];
                    obj2[0] = CALLBACK_TYPE_LIST;
                    obj2[1] = adapter;
                    onLoadListener.onLoad(obj2);
                }
            }

            @Override
            public void onFailure(String message) {
                if (mView == null) return;
                hideProgress();
            }
        });
    }

    private void hideProgress(){
        if (mView != null){
            mView.hideProgress();
        }
    }

    private class ConditionCallBack implements CallBack<ConditionBean> {

        @Override
        public void onSuccess(ConditionBean response, Context context, Object tag) {

        }

        @Override
        public void onFailure(String message) {
            mView.hideProgress();
        }
    }

    public void resetAdapterData(int type) {
        selectorAdapter.clear();
        ConditionBean.SelectorData allData = new ConditionBean.SelectorData();
        switch (type){
            case GoodsView.TYPE_STYLE:
                allData.setDicName("全部");
                allData.setParentId("0");
                selectorAdapter.add(allData);
                selectorAdapter.addAll(styleList);
                break;
            case GoodsView.TYPE_ROOM_TYPE:
                allData.setDicName("全部");
                selectorAdapter.add(allData);
                selectorAdapter.addAll(bandList);
                break;
        }
    }

    public void refreshShoppingCart(Context context){
        if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)){
            Map<String,Object> pa = new HashMap<String, Object>();
            pa.put(KEY_TOKEN,ConfigValue.DATA_KEY);
            pa.put(KEY_PHONE,SPUtils.get(context,SPConfig.PHONE,"").toString());
            goodsModel.getCartNum(context,pa, new CallBack<CartNum>() {
                @Override
                public void onSuccess(CartNum response, Context context, Object tag) {
                    if (mView == null) return;
                    if (response.getCode() == RESPONSE_CODE_SUC){
                        int num = response.getData().getNumber();
                        Object[] par = new Object[2];
                        par[0] = CALLBACK_TYPE_NUM;
                        par[1] = num;
                        onLoadListener.onLoad(par);
                        infoAdapter.setCartNum(num);
                    }
                }

                @Override
                public void onFailure(String message) {
                    if (mView == null) return;
                }
            });

        }
    }

}
